#include "BlockPart.h"


BlockPart::BlockPart(void)
{
}

void BlockPart::display(){}


//function to draw a texture cube
void BlockPart::drawCube(void)
{
	glTranslatef(-0.5, -0.5, -0.5);
	glColor3f(0.9, 0.9, 0.9);

	// vertices
	GLfloat A[] = { 0.0f, 1.0f, 1.0f }; 
	GLfloat B[] = { 1.0f, 1.0f, 1.0f }; 
	GLfloat C[] = { 1.0f, 1.0f, 0.0f }; 
	GLfloat D[] = { 0.0f, 1.0f, 0.0f }; 
	GLfloat E[] = { 0.0f, 0.0f, 1.0f }; 
	GLfloat F[] = { 1.0f, 0.0f, 1.0f }; 
	GLfloat G[] = { 1.0f, 0.0f, 0.0f }; 
	GLfloat H[] = { 0.0f, 0.0f, 0.0f }; 

	// texture coordinates
	GLfloat bottomLeft[] = {0.0f, 0.0f};
	GLfloat bottomRight[] = {1.0f, 0.0f};
	GLfloat topLeft[] = {0.0f, 1.0f};
	GLfloat topRight[] = {1.0f, 1.0f};

	// top
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 1.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(A);
		glTexCoord2fv(bottomRight);
		glVertex3fv(B);
		glTexCoord2fv(topRight);
		glVertex3fv(C);
		glTexCoord2fv(topLeft);
		glVertex3fv(D);
	glEnd();
	
	// bottom
	glBegin(GL_QUADS);
		glNormal3f( 0.0, -1.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(H);
		glTexCoord2fv(bottomRight);
		glVertex3fv(G);
		glTexCoord2fv(topRight);
		glVertex3fv(F);
		glTexCoord2fv(topLeft);
		glVertex3fv(E);
	glEnd();
	
	// Front
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 0.0, 1.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(E);
		glTexCoord2fv(bottomRight);
		glVertex3fv(F);
		glTexCoord2fv(topRight);
		glVertex3fv(B);
		glTexCoord2fv(topLeft);
		glVertex3fv(A);
	glEnd();

	// back
	glBegin(GL_QUADS);
		glNormal3f( 0.0, 0.0, -1.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(G);
		glTexCoord2fv(bottomRight);
		glVertex3fv(H);
		glTexCoord2fv(topRight);
		glVertex3fv(D);
		glTexCoord2fv(topLeft);
		glVertex3fv(C);
	glEnd();

	// left
	glBegin(GL_QUADS);
		glNormal3f( -1.0, 0.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(H);
		glTexCoord2fv(bottomRight);
		glVertex3fv(E);
		glTexCoord2fv(topRight);
		glVertex3fv(A);
		glTexCoord2fv(topLeft);
		glVertex3fv(D);
	glEnd();

	// right
	glBegin(GL_QUADS);
		glNormal3f( 1.0, 0.0, 0.0);
		glTexCoord2fv(bottomLeft);
		glVertex3fv(F);
		glTexCoord2fv(bottomRight);
		glVertex3fv(G);
		glTexCoord2fv(topRight);
		glVertex3fv(C);
		glTexCoord2fv(topLeft);
		glVertex3fv(B);
	glEnd();

}

BlockPart::~BlockPart(void)
{
}






//----------------------
// Plain obstacle block
//----------------------

PlainBlock::PlainBlock(void) {
	glColor3f(0.8,0.8,0.8);
	loadImage();
}

void PlainBlock::display(){
	glPushMatrix();
		glTranslatef(0,1,0);
		glBindTexture(GL_TEXTURE_2D, blockTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		drawCube();
	glPopMatrix();
}

void PlainBlock::loadImage() {
	//Image* image = loadBMP("textures\\plainblock.bmp");
	Image* image = loadBMP("textures\\pb.bmp");
	blockTexture = loadTexture(image);
	delete image;
}

PlainBlock::~PlainBlock(void)
{
}


//---------------------------
// Plain obstacle short-block
//---------------------------

PlainShortBlock::PlainShortBlock(void) {
	glColor3f(0.6,0.6,0.6);
	loadImage();
}

void PlainShortBlock::display(){
	glPushMatrix();
		glBindTexture(GL_TEXTURE_2D, blockTexture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		
		glTranslatef(0, 0.75,0);
		glScalef(1, 0.5, 1);
		drawCube();
	glPopMatrix();
}

void PlainShortBlock::loadImage() {
	//Image* image = loadBMP("textures\\plainblock.bmp");
	Image* image = loadBMP("textures\\psb.bmp");
	blockTexture = loadTexture(image);
	delete image;
}

PlainShortBlock::~PlainShortBlock(void)
{
}
